#include "OPENMV.h"

USART_TypeDef *OPENMV_USARTx;
OPENMVDataStruct OPENMV;
bool openmv_exist = false;

void OPENMV_init(USART_TypeDef *USARTx, uint32_t baud)
{
    OPENMV_USARTx = USARTx;
    UARTx_init(USARTx, baud);
    openmv_exist = true;
}

// bool OPENMV_bufOverflow()
// {
//     return UARTx_bufAvailable(OPENMV_USARTx);
// }

bool OPENMV_sendByte(const uint8_t byte)
{
    return UARTx_sendByte(OPENMV_USARTx, byte);
}

bool OPENMV_sendString(uint8_t *str)
{
    return UARTx_sendString(OPENMV_USARTx, str);
}

bool OPENMV_receiveString(uint8_t **str)
{
    return UARTx_receiveString(OPENMV_USARTx, str);
}

bool OPENMV_unZip(uint8_t *str)
{
    float *p = (float *)&(str[4]);
    if (str[0] != 0xA5 || str[1] != 0xA6)
    {
        return false;
    }
    OPENMV.xa = str[2];
    OPENMV.xb = str[3];
    OPENMV.region1 = str[8];
    OPENMV.turnflag = str[9];
    OPENMV.theta = *p;
}
